<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>作业列表</title>
    <meta name="viewport"
          content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0"/>

    <link rel="stylesheet" href="../js/libs/sui/sm.min.css">
    <link rel="stylesheet" href="../js/libs/sui/sm-extend.min.css">
    <link rel="stylesheet" href="../iconfont/iconfont.css">
    <link rel="stylesheet" href="../less/main.css"/>

    <script type="text/javascript" src='../js/libs/jquery-3.1.0.min.js' charset='utf-8'></script>
    <script type="text/javascript">
        var Zepto = jQuery;
    </script>
    <script type="text/javascript" src='../js/libs/sui/sm.js' charset='utf-8'></script>
    <script type="text/javascript" src='../js/libs/sui/sm-extend.min.js' charset='utf-8'></script>
    <script type="text/javascript" src="../js/libs/juicer-min.js"></script>
    <script type="text/javascript" src="../js/libs/jquery.md5.js"></script>
    <script type="text/javascript" src="../js/api.js"></script>
    <script type="text/javascript" src="../js/utils.js"></script>
    <script type="text/javascript" src="../js/common.js"></script>
</head>
<body>
<!-- 这里是页面内容区 -->
<div id="page" class="page">
    <!-- 头部-->
    <div class="head-no-toolbar bg-self-green no-left-icon">
        <span class="icon iconfont c-white p-l" onclick="javascript:api.closeWin();">&#xe61f;</span>
        <span class="c-white t-center ">
            作业列表
            <span class="upload-homework-button t-right c-white pos-abs">上传</span>
        </span>
    </div>
    <div class="content pull-to-refresh-content" data-ptr-distance="20" style="top: 0;">
        <div class="pull-to-refresh-layer">
            <div class="preloader"></div>
            <div class="pull-to-refresh-arrow"></div>
        </div>
        <div class="list-block media-list list-job job-tool focus-company">
            <!--<ul>-->
                <!--<li>-->
                    <!--<a load="public/pag../company-info.html" class="my-company-info" progress="false">-->
                        <!--<div class="item-content">-->
                            <!--<div class="item-media item-pb-0"><img-->
                                    <!--src="http://gqianniu.alicdn.com/bao/upload..//tfsc../TB10LfcHFXXXXXKXpXXXXXXXXXX_!!0-item_pic.jpg_250x250q60.jpg"-->
                                    <!--style='width: 3rem;'></div>-->
                            <!--<div class="item-inner item-pb-0">-->
                                <!--<div class="item-title-row">-->
                                    <!--<div class="item-title c-default">贵州安云科技有限公司</div>-->
                                <!--</div>-->
                                <!--<div class="item-subtitle">以软件、产品开发为主导，集产品研发研发</div>-->
                            <!--</div>-->
                        <!--</div>-->
                    <!--</a>-->
                <!--</li>-->
                <!--<div class="item-foot1">-->
                    <!--<a class="cancel"><i class="icon iconfont c-red">&#xe61c;</i>取消关注</a>-->

                    <!--<div class="pull-right">-->
                        <!--<a href="" class="my-company-info">查看详细 <span class="icon iconfont">&#xe620;</span></a>-->
                    <!--</div>-->
                <!--</div>-->
            <!--</ul>-->
            <!--<ul>-->
                <!--<li>-->
                    <!--<a load="public/pag../company-info.html" class="my-company-info" progress="false">-->
                        <!--<div class="item-content">-->
                            <!--<div class="item-media item-pb-0"><img-->
                                    <!--src="http://gqianniu.alicdn.com/bao/upload..//tfsc../TB10LfcHFXXXXXKXpXXXXXXXXXX_!!0-item_pic.jpg_250x250q60.jpg"-->
                                    <!--style='width: 3rem;'></div>-->
                            <!--<div class="item-inner item-pb-0">-->
                                <!--<div class="item-title-row">-->
                                    <!--<div class="item-title c-default">贵州安云科技有限公司</div>-->
                                <!--</div>-->
                                <!--<div class="item-subtitle">以软件、产品开发为主导，集产品研发研发</div>-->
                            <!--</div>-->
                        <!--</div>-->
                    <!--</a>-->
                <!--</li>-->
                <!--<div class="item-foot1">-->
                    <!--&lt;!&ndash;<a class="cancel"><i class="icon iconfont c-red">&#xe61c;</i>取消关注</a>&ndash;&gt;-->
                    <!--<a class="cancel"><span class="icon iconfont icon-shanchu" style="top:-2px"></span>取消关注</a>-->

                    <!--<div class="pull-right">-->
                        <!--<a href="" class="my-company-info">查看详细 <span class="icon iconfont">&#xe620;</span></a>-->
                    <!--</div>-->
                <!--</div>-->
            <!--</ul>-->
        </div>
    </div>
</div>
<script id="focus-company-tpl" type="text/template">
    {@each homeworkList as it,index}
    <ul>
        <li>
            <a data-task-id="&{it.TASK_ID}" class="my-company-info" progress="false">
                <div class="item-content">
                    <div class="item-inner item-pb-0">
                        {@if (it.TITLE_SETS != null) && (it.TITLE_SETS != '')}
                        <div class="item-title-row">
                            <div class="item-title c-default">我的作业</div>
                        </div>
                        {@/if}

                        <!--{@if (it.TITLE_TYPE != null) && (it.TITLE_TYPE != '')}-->
                        <!--<div class="item-subtitle">&{it.TITLE_TYPE}</div>-->
                        <!--{@/if}-->
                    </div>
                </div>
            </a>
        </li>
        <div class="item-foot1">
            <a data-task-id="&{it.TASK_ID}" class="cancel"><span class="icon iconfont icon-shanchu" style="top:-2px"></span>删除作业</a>

            <div class="pull-right">
                <a data-task-id="&{it.TASK_ID}" class="my-company-info">查看详细<span class="icon iconfont">&#xe620;</span></a>
            </div>
        </div>
    </ul>
    {@/each}
</script>
<script type="text/javascript">
    apiready = function () {
        juicer.set({
            'tag::operationOpen': '{@',
            'tag::operationClose': '}',
            'tag::interpolateOpen': '&{',
            'tag::interpolateClose': '}',
            'tag::noneencodeOpen': '$${',
            'tag::noneencodeClose': '}',
            'tag::commentOpen': '{#',
            'tag::commentClose': '}',
            'strip': false,
            'cache': false
        });

        //接收传来的班级id
        var clazzId = api.pageParam.clazzId;

        // 查询数据 SQL
        var sql = "select * from stu_task where CLASS_ID='{0}' and STUDENT_ID='{1}'";

        getData(true);

        //获取数据
        function getData(progressFlag) {

            //获取学生信息
            var stuInfo = getLoginStudentInfo();
            //获取登陆用户id
            var studentId = stuInfo.STUDENT_ID;

            if (isObject(stuInfo) && isNumber(studentId)) {
                dbQuery(1, 10, sql.format(clazzId, studentId), progressFlag, function (ret, err) {
                    if (isObject(ret) && (ret.statusCode == 0)) {
                        if (ret.result.length != 0) {
                            var homeworkData = {
                                homeworkList: ret.result
                            };

                            $(".focus-company").html(juicer($("#focus-company-tpl").html(), homeworkData));
                        } else {
                            toast("暂无作业");
                        }
                    }
                });
            }
        }

        //删除作业
        function delHomework(taskId) {

            var sqlFile = "delete from stu_task_file where TASK_ID='{0}'";


            //先删除图片表
            dbExecute(sqlFile.format(taskId), false, function (ret, err) {
                if (isObject(ret) && ret.statusCode == 0) {

                    doDelete(taskId);
                } else {
                    toast("删除作业失败");
                }
            });
        }

        //删除作业表
        function doDelete(taskId) {
            var sql = "delete from stu_task where TASK_ID='{0}'";
            //先删除图片表
            dbExecute(sql.format(taskId), false, function (ret, err) {
                if (isObject(ret) && ret.statusCode == 0) {

                    toast("删除作业成功");
                    //刷新页面
                    location.reload();
                } else {
                    toast("删除作业失败");
                }
            });
        }

        //点击进入详细界面
        $(".focus-company").on("click", ".my-company-info", function () {
            var $this = $(this);
            var taskId = $this.data("taskId");
            openWin("my-homework-detail", "my-homework-detail.html", {
                taskId: taskId
            });
        });

        //删除作业按钮
        $(".focus-company").on("click", ".cancel", function () {
            var $this = $(this);
            var taskId = $this.data("taskId");
            var r = confirm("确认是否删除");
            if (r == true) {
                delHomework(taskId);
            }
        });

        //上传按钮
        $("#page").on("click", ".upload-homework-button", function () {

            openWin("add-homework", "add-homework.html", {
                clazzId: clazzId
            });
        });


        //监听事件
        api.addEventListener({
            name: "workEvent"
        }, function (ret, err) {
            //刷新页面
            location.reload();
        });


        // 页数
        var mjyPage = 1;

        // 下拉刷新
        $(document).on("refresh", ".pull-to-refresh-content", function () {

            var stuInfo = getLoginStudentInfo();
            var studentId = stuInfo.STUDENT_ID;

            if (isObject(stuInfo) && isNumber(studentId)) {
                mjyPage++;

                dbQuery(mjyPage, 10, sql.format(studentId), false, function (ret, err) {
                    if (isObject(ret) && (ret.statusCode == 0)) {
                        var homeworkData = {
                            homeworkList: ret.result
                        };

                        if (homeworkData.homeworkList.length > 0) {
                            $(".focus-company").prepend(juicer($("#focus-company-tpl").html(), homeworkData));
                        } else {
                            toast("已加载完毕");

                            mjyPage--;
                        }
                    }

                    $.pullToRefreshDone(".pull-to-refresh-content");
                });
            }
        });
    };
</script>
<script>$.init();</script>
</body>
</html>
